home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13056 < prev    next >
Encoding:
Text File  |  1996-08-05  |  3.5 KB  |  164 lines

  1. Path: newsfeed.internetmci.com!rbdc!usenet
  2. From: marty1@rbdc.rbdc.com (Jumping Jack Flash)
  3. Newsgroups: comp.lang.c
  4. Subject: Help with a very weird C problem
  5. Date: Wed, 03 Apr 1996 06:49:45 GMT
  6. Organization: Red Barn Data Center, Winston-Salem, NC.
  7. Message-ID: <31620c87.184254741@199.171.83.2>
  8. NNTP-Posting-Host: rbdc6.rbdc.com
  9. X-Newsreader: Forte Agent .99d/32.168
  10.  
  11. Ok here's the problem. This program works great. BUT when I'm in the
  12. c:\windows\desktop\programs directory instead of running the pkunzip
  13. program it just shells a command.com, then after I type exit it
  14. displays the ending screen. Here's the code
  15.  
  16. #include <stdlib.h>
  17. #include <conio.h>
  18. #include <iostream.h>
  19. #include <string.h>
  20. #include <dir.h>
  21. #include <process.h>
  22. #include <stdio.h>
  23. #include <errno.h>
  24. #define TRUE 1
  25. #define FALSE 0
  26.  
  27. char *PkunzipDir(char *curdir,char *name2,char *file);
  28. char *Current_Directory(char *path);
  29.  
  30. int main(int argc, char **argv)
  31. {
  32. clrscr();
  33. char drive[MAXDRIVE];
  34. char dir[MAXDIR];
  35. char file[MAXFILE];
  36. char ext[MAXEXT];
  37. char curdir[MAXPATH];
  38. char *pkunzip_search;
  39. struct ffblk ffblk;
  40. int done, stat;
  41.  
  42. //Searches all current dos paths for pkunzip
  43. pkunzip_search = searchpath("pkunzip.exe");
  44. if(pkunzip_search == NULL)
  45.     {
  46.     clrscr();
  47.     cout << "PKUNZIP.EXE must be in your dos path!";
  48.     exit(EXIT_FAILURE);
  49.     }
  50.  
  51. //Gets Current Directory & searches for first .zip file
  52. Current_Directory(curdir);
  53.  
  54. if(argc == 2)
  55.     {
  56.     done = findfirst(argv[1],&ffblk,0);
  57.     if(done)
  58.         {
  59.          clrscr();
  60.          cout << "No Zipped files in current Directory\n";
  61.         }
  62.     else
  63.         {
  64.         while (!done)
  65.             {
  66.             fnsplit(ffblk.ff_name,drive,dir,file,ext);
  67.             stat = mkdir(file);
  68.             if (!stat)
  69.                 {
  70.                 cout << "\n" << "Directory " << file
  71. << " created\n";
  72.                 cout << "Unzipping Files into it\n";
  73.  
  74. system(PkunzipDir(curdir,ffblk.ff_name,file));
  75.                 }
  76.  
  77.             else
  78.                 {
  79.                 clrscr();
  80.                 cout << "Unable to create directory "
  81. << file << "\n";
  82.                 cout << "For zipped file " << file <<
  83. ext;
  84.                 }
  85.             done = findnext(&ffblk);
  86.             }
  87.         }
  88.     }
  89.   else//A1
  90.     {
  91.     done = findfirst("*.zip",&ffblk,0);
  92.     if(done)
  93.         {
  94.          clrscr();
  95.          cout << "No Zipped files in current Directory\n";
  96.         }
  97.     else//A2
  98.         {
  99.         while (!done)
  100.             {
  101.             fnsplit(ffblk.ff_name,drive,dir,file,ext);
  102.             stat = mkdir(file);
  103.             if (!stat)
  104.                 {
  105.                 cout << "\n" << "Directory " << file
  106. << " created\n";
  107.                 cout << "Unzipping Files into it\n";
  108.  
  109. system(PkunzipDir(curdir,ffblk.ff_name,file));
  110.                 }
  111.             else
  112.                 {
  113.                 clrscr();
  114.                 cout << "Unable to create directory "
  115. << file << "\n";
  116.                 cout << "For zipped file " << file <<
  117. ext;
  118.                 }
  119.             done = findnext(&ffblk);
  120.             }//Ends While
  121.         }//Ends Else A2
  122.     }//End Else A1
  123. cout <<"\n" << "This program is Freeware\n";
  124. cout << "Written by Marty A. Lineberry\n";
  125. cout << "Internet address marty1@rbdc.rbdc.com\n";
  126. cout << "End of Program\n";
  127. return 0;
  128. }
  129.  
  130.  
  131.  
  132. char *PkunzipDir(char *curdir,char *name2,char *file)
  133. {
  134. char pkunzip2[120] = "pkunzip ";
  135. strcat(pkunzip2,curdir);
  136. strcat(pkunzip2,name2);
  137. strcat(pkunzip2," ");
  138. strcat(pkunzip2,curdir);
  139. strcat(pkunzip2,file);
  140. return(pkunzip2);
  141. }
  142.  
  143. //**********************************************************
  144. //* Used to get the current Drive & Directory              *
  145. //**********************************************************
  146. char *Current_Directory(char *path)
  147. {
  148.    strcpy(path, "X:\\");      /* fill string with form of response:
  149. X:\ */
  150.    path[0] = 'A' + getdisk();    /* replace X with current drive
  151. letter */
  152.    getcurdir(0, path+3);  /* fill rest of string with current
  153. directory */
  154.    if(strlen(path) > 3) /* Puts ending / if not root directory */
  155.     {
  156.     strcat(path,"\\");
  157.     }
  158.    return(path);
  159. }
  160.  
  161.  
  162.  
  163.  
  164.